/**
 *
 */
package de.cbf.cam.dsa.rcp.model.entities.items;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import de.cbf.cam.dsa.item.model.entities.Item;
import de.cbf.cam.dsa.item.model.entities.constants.ResolveAttributesConstants;
import de.cbf.cam.dsa.rcp.model.entities.CultureDSA;
import de.cbf.util.uuidheader.entities.EntityWeighted;
import de.cbf.util.uuidheader.entities.UUIDReference;
import de.cbf.util.uuidheader.util.EntityWeightedList;

/**
 * @author salter
 *
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CultureItemDSA extends CultureDSA {

	public static final String KEY_CLOTHING 			= ResolveAttributesConstants.ATTRIBUTE_CLOTHING;
	public static final String KEY_CLOTHING_UNDERWEAR 	= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_UNDERWEAR;
	public static final String KEY_CLOTHING_HAT			= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_HAT;
	public static final String KEY_CLOTHING_SHIRT		= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_SHIRT;
	public static final String KEY_CLOTHING_JACKET		= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_JACKET;
	public static final String KEY_CLOTHING_CLOAK		= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_CLOAK;
	public static final String KEY_CLOTHING_TROUSERS	= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_TROUSERS;
	public static final String KEY_CLOTHING_SHOES		= ResolveAttributesConstants.ATTRIBUTE_CLOTHING_SHOES;

	public static final String KEY_WEAPON_TYPICAL 	= ResolveAttributesConstants.ATTRIBUTE_WEAPON;
	public static final String KEY_WEAPON_MELEE 	= ResolveAttributesConstants.ATTRIBUTE_WEAPON_MELEE;
	public static final String KEY_WEAPON_RANGED 	= ResolveAttributesConstants.ATTRIBUTE_WEAPON_RANGED;

	protected Map<String, EntityWeightedList> cultureItems;

	@Override
	protected void init() {
		super.init();
		cultureItems = new HashMap<String, EntityWeightedList>();
	}

	public Map<String, EntityWeightedList> getCultureItems() {
		return cultureItems;
	}

	public EntityWeightedList getTypedCultureItems(String typeKey){
		return cultureItems.get(typeKey);
	}

	public void addCultureItemReference(String typeKey,UUIDReference item, Double weight){
		EntityWeighted entity = new EntityWeighted(item, weight);
		addCultureItemReference(typeKey, entity);
	}


	public void addCultureItemReference(String typeKey,EntityWeighted entity){
		if (entity.getEntity() instanceof UUIDReference) {
			boolean newlyCreatedValue = false;
			EntityWeightedList list = cultureItems.get(typeKey);
			if(list == null){
				newlyCreatedValue = true;
				list = new EntityWeightedList();
			}
			list.add(entity);
			if(newlyCreatedValue){
				cultureItems.put(typeKey, list);
			}
		}
	}

	public void removeCultureItem(String typeKey,Item item, Double weight){
		EntityWeighted entity = new EntityWeighted(item, weight);
		removeCultureItem(typeKey, entity);
	}

	public void removeCultureItem(String typeKey,EntityWeighted entity){
		EntityWeightedList list = cultureItems.get(typeKey);
		if(list != null){
			list.remove(entity);
		}
	}


}
